package org.springframework.beans.factory.exception;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InjectionPoint;
import org.springframework.beans.factory.exception.BeanCreationException;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;

@SuppressWarnings("serial")
public class UnsatisfiedDependencyException extends BeanCreationException {

	@Nullable
	private InjectionPoint injectionPoint;

	public UnsatisfiedDependencyException(@Nullable String resourceDescription, @Nullable String beanName, String propertyName, String msg) {
		super(resourceDescription, beanName, "Unsatisfied dependency expressed through bean property '" + propertyName + "'" + (StringUtils.hasLength(msg) ? ": " + msg : ""));
	}

	public UnsatisfiedDependencyException(@Nullable String resourceDescription, @Nullable String beanName, String propertyName, BeansException ex) {
		this(resourceDescription, beanName, propertyName, "");
		initCause(ex);
	}

	public UnsatisfiedDependencyException(@Nullable String resourceDescription, @Nullable String beanName, @Nullable InjectionPoint injectionPoint, String msg) {
		super(resourceDescription, beanName, "Unsatisfied dependency expressed through " + injectionPoint + (StringUtils.hasLength(msg) ? ": " + msg : ""));
		this.injectionPoint = injectionPoint;
	}

	public UnsatisfiedDependencyException(@Nullable String resourceDescription, @Nullable String beanName, @Nullable InjectionPoint injectionPoint, BeansException ex) {
		this(resourceDescription, beanName, injectionPoint, "");
		initCause(ex);
	}

	@Nullable
	public InjectionPoint getInjectionPoint() {
		return this.injectionPoint;
	}
}
